<template>
  <section class="one-key-bill">
    <process-statistics :data-list="processStatisticsData"/>
    <section class="common-block-section">
      <type-table :type="5" />
      <!-- <el-tabs v-model="activedName">
        <el-tab-pane label="一般纳税人" name="first">
          <type-table :type="0" />
        </el-tab-pane>
        <el-tab-pane label="小规模纳税人" name="second">
          <type-table :type="1" />
        </el-tab-pane>
      </el-tabs> -->
    </section>
  </section>
</template>

<script>
/**
 * @file 一键报税
 */
import processStatistics from "@/components/process-statistics";
import typeTable from "./typeTable";
import utiles from '@/components/utiles';

export default {
  components: {
    processStatistics,
    typeTable,
  },
  data() {
    return {
      activedName: "first",
      // 进度统计数据
      processStatisticsData: []
    };
  },
  mounted() {
    this.loadData();
  },
  methods: {
    handleClick(tab, event) {
    },
    async loadData() {
      var myDate = new Date();
      var tYear = myDate.getFullYear();
      var tMonth = myDate.getMonth();
      var m = tMonth + 1;
      if (m.toString().length == 1) {
          m = "0" + m;
      }
      const currentUser = utiles.getCurrentUser();
      var params = {
          bName:currentUser.bCompanyName,
          type: 5
      }
      const res = await this.$http.get('/incomeTax/statistics', {params: params})
      if (res.code !== 0) return this.$message.error(res.message);
        console.log("statis:", res.data)
      let sum = 0;
      res.data.forEach(element => {
          sum += element.number
      });

      var statisList = res.data.map(item => {
        console.log("百分比：", [item.name, [(item.number/sum * 100).toFixed(2), item.number]]);
          return [item.name, [Math.round(item.number/sum * 1000000) / 10000, item.number]]
      });

      var originmap = new Map(statisList);
      this.processStatisticsData = 
      {left:
        [{
          number:sum,
          percent:100,
          title: "缴税总数"
        },
        {
          number:this.number(originmap,"缴纳成功"),
          percent:this.round4Remain2(this.percent(originmap,"缴纳成功")),
          title: "缴纳成功"
        }],
        right:[
          {
            number: this.number(originmap, "待申报") + this.number(originmap, "申报中") + this.number(originmap,"申报失败"),
            percent: this.round4Remain2(this.percent(originmap,"待申报") + this.percent(originmap,"申报中") + this.percent(originmap,"申报失败")),
            title: "申报环节",
            childrenData:[
              {persent:this.percent(originmap, "待申报"), title:"待申报", value: this.number(originmap, "待申报")},
              {persent:this.percent(originmap,"申报中"), title:"申报中", value: this.number(originmap,"申报中")}, 
              {persent:this.percent(originmap, "申报失败"), title:"申报失败", value: this.number(originmap, "申报失败")}
            ]
          },
          {
            number: this.number(originmap,"申报成功(待客户确认)") + this.number(originmap,"确认中") + this.number(originmap, "人工处理"),
            percent: this.round4Remain2(this.percent(originmap,"申报成功(待客户确认)") + this.percent(originmap,"确认中") + this.percent(originmap,"人工处理")),
            title: "客户确认环节",
            childrenData:[
              {persent: this.percent(originmap,"申报成功(待客户确认)"), title:"申报成功(待确认)", value: this.number(originmap,"申报成功(待客户确认)")},
              {persent: this.percent(originmap,"确认中"), title:"确认中", value: this.number(originmap,"确认中")},
              {persent: this.percent(originmap,"人工处理"), title:"人工处理", value: this.number(originmap,"人工处理")}
            ]
          },
          {
            number: this.number(originmap,"缴纳中") + this.number(originmap,"缴纳成功") + this.number(originmap,"无三方协议") + this.number(originmap,"缴纳失败"),
            percent: this.round4Remain2(this.percent(originmap,"缴纳中") + this.percent(originmap,"缴纳成功") + this.percent(originmap,"无三方协议")+ this.percent(originmap,"缴纳失败")),
            title: "缴纳环节",
            childrenData:[
              {persent: this.percent(originmap, "缴纳中"), title:"缴纳中", value: this.number(originmap, "缴纳中")},
              {persent: this.percent(originmap,"缴纳成功"), title:"缴纳成功", value: this.number(originmap,"缴纳成功")},
              {persent: this.percent(originmap,"无三方协议"), title:"无三方协议", value: this.number(originmap,"无三方协议")},
               {persent: this.percent(originmap,"缴纳失败"), title:"缴纳失败", value: this.number(originmap,"缴纳失败")},
            ]
          }
        ]
      };
  },
  percent(originmap, title){
    console.log("percent:", title, originmap);
    if(originmap.get(title) == undefined){
      return 0;
    } else {
      return originmap.get(title)[0]
    }
  },
  number(originmap, title){
    if(originmap.get(title) == undefined){
      return 0;
    } else {
      return originmap.get(title)[1]
    }
  },
  round4Remain2(number){
    return Math.round(number*100) / 100;
  },
  },
};
</script>

<style lang="less" scoped>
.one-key-bill {
  padding: 0 10px;
  .top-line {
    padding-bottom: 10px;
  }
  .pagination {
    text-align: right;
    padding: 20px 0 0;
  }
}
</style>
